package com.qfoud.edu.framwork.stragy.impl;

import com.qfoud.edu.framwork.pojo.BeanParameterDefinition;
import com.qfoud.edu.framwork.pojo.Model;
import com.qfoud.edu.framwork.stragy.base.ParameterTypeStragy;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author xiaobobo
 * @title: StringArrayStragy
 * @projectName cd-java-2303-project-parent
 * @description: TODO
 * @date 2023/5/10  15:32
 */
public class StringArrayStragy implements ParameterTypeStragy {
    @Override
    public void run(Model model, HttpServletResponse resp, BeanParameterDefinition beanParameterDefinition, HttpServletRequest req, int index, String parameterType, String parameterName, Object... args) {
        //说明需要的是一个String类型的数组来接受参数的
        stringArrayTypeParameterSet(req, index, parameterType, parameterName, args);
    }

    /**
     * 这个说明需要将前端的参数封装成String类型的数组
     * @param req
     * @param index
     * @param parameterType
     * @param parameterName
     * @param args
     */
    private void stringArrayTypeParameterSet(HttpServletRequest req, int index,
                                             String parameterType, String parameterName, Object[] args) {
        String[] parameterValues = req.getParameterValues(parameterName);
        args[index]=parameterValues;
    }
}
